package com.yy.jhl.ui.manager.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.yy.common.base.BaseAdapter;
import com.yy.common.commonutils.StringUtil;
import com.yy.jhl.R;
import com.yy.jhl.bean.InvitePackageInfo;
import com.yy.jhl.bean.InvitePackageInfo.ItemsBean;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Ellis.Li on 2017/6/15.
 */

public class InviteBoxInfoAdapter extends BaseAdapter {
    private List<InvitePackageInfo.ItemsBean> modelList;
    public InviteBoxInfoAdapter(Context context) {
        super(context);
        modelList = new ArrayList<>();
    }
    @Override
    public void removeItem(int position) {
        super.removeItem(position);
        modelList.remove(position);
        notifyDataSetChanged();
    }
    @Override
    public void clearData() {
        super.clearData();
        modelList.clear();
        notifyDataSetChanged();
    }
    public void addData(List<InvitePackageInfo.ItemsBean> monomerModels) {
        modelList.addAll(monomerModels);
        notifyDataSetChanged();
    }

    public void addAllData(List<InvitePackageInfo.ItemsBean> monomerModels) {
        clearData();
        modelList.addAll(monomerModels);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return modelList.size();
    }

    @Override
    public Object getItem(int i) {
        return modelList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        Holder storeHolder;
        if(view == null){
            storeHolder = new Holder();
            view = layoutInflater.inflate(R.layout.item_invite_box,null);
            storeHolder.initView(view);
            view.setTag(storeHolder);
        }else{
            storeHolder = (Holder)view.getTag();
        }
        final InvitePackageInfo.ItemsBean itemModel = modelList.get(i);
        storeHolder.a_text.setText(itemModel.getItem_name());
        storeHolder.b_text.setText(itemModel.getModel());
        storeHolder.c_text.setText(itemModel.getQuantity());
        storeHolder.d_text.setText(itemModel.getUnit());
        storeHolder.e_text.setText(itemModel.getUnit_price());
        String allPrice = "";
        try {
         allPrice = StringUtil.getSingleDouble(Double.parseDouble(itemModel.getQuantity())*Double.parseDouble(itemModel.getUnit_price()));
        }catch (Exception e){
            allPrice = "0.0" ;
        }
        storeHolder.f_text.setText(allPrice);
        return view;
    }
    /**
     *
     */
    class Holder{
        private TextView a_text;
        private TextView b_text;
        private TextView c_text;
        private TextView d_text;
        private TextView e_text;
        private TextView f_text;
        void initView(View view) {
            a_text = (TextView) view.findViewById(R.id.a_text);
            b_text = (TextView) view.findViewById(R.id.b_text);
            c_text = (TextView) view.findViewById(R.id.c_text);
            d_text = (TextView) view.findViewById(R.id.d_text);
            e_text = (TextView) view.findViewById(R.id.e_text);
            f_text = (TextView) view.findViewById(R.id.f_text);
        }

    }
}
